
package com.kcdown.train;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kcdown.train.util.GoogleSearchResult;

public class TicketBoothAdapter extends BaseAdapter {
	public TicketBoothAdapter(Context c) {
		iInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	private ArrayList<GoogleSearchResult> 	iResults;
	private LayoutInflater 					iInflater = null;

	@Override
	public int getCount() {
		if (iResults != null) {
			return iResults.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	private static class ViewHolder {
		TextView iTitle;
		TextView iAddress;
		TextView iPhoneNum;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;

		if (convertView == null) 
		{
			holder = new ViewHolder();
			convertView = iInflater.inflate(R.layout.item_ticketbooth, null);
			holder.iTitle = (TextView) convertView.findViewById(R.id.tt_title);
			holder.iAddress = (TextView) convertView.findViewById(R.id.tt_address);
			holder.iPhoneNum = (TextView) convertView.findViewById(R.id.tt_phone);
		} else 
		{
			holder = (ViewHolder) convertView.getTag();
		}
		GoogleSearchResult result = iResults.get(position);
		
		holder.iTitle.setText(result.getTitle());
		holder.iAddress.setText(result.getAddress());
		holder.iPhoneNum.setText(result.getPhoneNumber());
		convertView.setTag(holder);
		//convertView.setOnClickListener(viewOnClick);
		return convertView;
	}

	public ArrayList<GoogleSearchResult> getResults() {
		return iResults;
	}

	public void setResults(ArrayList<GoogleSearchResult> rsts) {
		this.iResults = rsts;
		notifyDataSetChanged();
	}

	public void Stations(GoogleSearchResult rst) {
		if (iResults == null) {
			iResults = new ArrayList<GoogleSearchResult>();
		}
		iResults.add(rst);
	}

}